﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cit.CDE.Net.Module.Commons;
using Module;
using Cit.CDE.Net.Module;
using cde.SystemCommon;
using UI.UserControl;
using Cit.CDE.Net.Service.ModuleFactory;
using System.Web.UI.HtmlControls;
using System.Text;
using ConfigAndElse;

/// <summary>
/// Copyright (C)   jinggubang
/// FileName:        CourseIndex.aspx.cs           
/// Author :         Wangbc
/// CDT:             2013-02-01           
/// Version:         1.0.0.0                
/// Depiction:       课件首页  
/// </summary>
public partial class main_admin_CourseIndex : UserControl.CommonPage
{
    
    protected void Page_Load(object sender, EventArgs e)
    {

        //查询下载最多课件
        CDEEntityManager courseEm = CDEEMFactory.getEMByFullName("WEB.CSW_MANAGE");

        LoginOprator op = (LoginOprator)Session[Cit.CDE.Net.Module.Commons.CDEConstants.SESSION_LOIN_OPRATOR];

        CDESearchCriteria courseSc = new CDESearchCriteria(courseEm);
        courseSc.addCondition("DEL_FLG", "0");
        //courseSc.addCondition("STATE", "0");
        courseSc.addCondition("INSERT_USER", op.SysID);

        courseSc.PageSize = 12;       
        courseSc.addSortOrder("INSERT_DATE", "DESC");
        courseSc.addSortOrder("DOWNLOADS", "DESC");
        List<CDEEntity> courseList = CDEService.LoadEntities(courseEm, courseSc);
        StringBuilder corseStr = new StringBuilder();
        foreach (CDEEntity entity in courseList)
        {
            string NAME = Util.objectToString(entity.get("NAME"));
            string FILE_TYPE = Util.objectToString(entity.get("FILE_TYPE"));
            string ID = Util.objectToString(entity.get("CSW_ID"));
            string fileImage = Util.getImageByFileType(FILE_TYPE.ToLower());
             corseStr.AppendFormat("<ul class=\"geshi\">");
             corseStr.AppendFormat("<li class=\"geshi_1\"><a href=\"DownloadCourse.aspx?CSW_ID={0}\"><img src=\"{1}\" /></a></li>", ID, fileImage);
             corseStr.AppendFormat("<li class=\"geshi_2\"><a href=\"DownloadCourse.aspx?CSW_ID={0}\">{1}</a></li>", ID, NAME);
             corseStr.AppendFormat("</ul>");
        }

        corseStr.Append("<div style=\"clear:both;\"></div>");
        courseListDiv.InnerHtml = corseStr.ToString();

        //共享课件
        CDESearchCriteria courseSc2 = new CDESearchCriteria(courseEm);
        courseSc2.addCondition("DEL_FLG", "0");
        courseSc2.addCondition("AUDIT_STATE", "1");
        courseSc2.addCondition("STATE", "0");
       
        courseSc2.PageSize = 6;
        courseSc2.addSortOrder("INSERT_DATE", "DESC");
        courseSc2.addSortOrder("DOWNLOADS", "DESC");
        List<CDEEntity> courseList2 = CDEService.LoadEntities(courseEm, courseSc2);
        StringBuilder corseStr2 = new StringBuilder();
        foreach (CDEEntity entity in courseList2)
        {
            string NAME = Util.objectToString(entity.get("NAME"));
            string FILE_TYPE = Util.objectToString(entity.get("FILE_TYPE"));
            string ID = Util.objectToString(entity.get("CSW_ID"));
            string fileImage = Util.getImageByFileType(FILE_TYPE.ToLower());
            corseStr2.AppendFormat("<ul class=\"geshi\">");
            corseStr2.AppendFormat("<li class=\"geshi_1\"><a href=\"DownloadCourse.aspx?CSW_ID={0}\"><img src=\"{1}\" /></a></li>", ID, fileImage);
            corseStr2.AppendFormat("<li class=\"geshi_2\"><a href=\"DownloadCourse.aspx?CSW_ID={0}\">{1}</a></li>", ID, NAME);
            corseStr2.AppendFormat("</ul>");
        }

        corseStr2.Append("<div style=\"clear:both;\"></div>");       
        courseListDiv2.InnerHtml = corseStr2.ToString();


        //查询最新通知
        CDEEntityManager sysmsgEm = CDEEMFactory.getEMByFullName("WEB.MSG_MANAGE");
        CDESearchCriteria sysmsgSc = new CDESearchCriteria(sysmsgEm);
        sysmsgSc.addCondition("DEL_FLG", "0");
        sysmsgSc.PageSize = 10;
        sysmsgSc.addSortOrder("INSERT_DATE", "DESC");
        List<CDEEntity> sysmsgList = CDEService.LoadEntities(sysmsgEm, sysmsgSc);
        StringBuilder sysmsgStr = new StringBuilder();
        foreach (CDEEntity entity in sysmsgList)
        {
            string MSG_TITLE = Util.objectToString(entity.get("MSG_TITLE"));
            string INSERT_DATE = Util.objectToString(entity.get("INSERT_DATE"));
            string msg_id = Util.objectToString(entity.get("MSG_ID"));
            sysmsgStr.AppendFormat("<LI><a href=\"javascript:openwin('../admin/MsgView.aspx?chkID={0}&viewType=1')\">{1}</a></LI>", msg_id, MSG_TITLE);
        }

        sysmsgListDiv.InnerHtml = sysmsgStr.ToString();
    } 
    
}
